package br.com.lucasoliveira.modules.contratos;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class DoubleSigRemover {
	public DoubleSigRemover() {

	}
	

	public Map<String, String> getSigsMap(File patch) {
		HashMap<String, String> toReturn = new HashMap<String, String>();
		for (File file : patch.listFiles()) {
			if (file.getName().endsWith(".sig")) {
				toReturn.put(file.getName().split("_")[2], file.getAbsolutePath());
			}
		}
		return toReturn;
	}

	public void separaArquivosUnicos(Set<Entry<String, String>> keys,String newPatch){
		for (Entry<String, String> entry : keys) {
			File sig = new File(entry.getValue());
			String sigFolder = sig.getName().split("_")[1];
			File newSig = new File(newPatch+File.separatorChar+sigFolder);
			if(!newSig.exists()){
				newSig.mkdir();
			}
			System.out.println("Movendo o arquivo: "+sig.getAbsolutePath()+" para: "+newSig.getAbsolutePath());
			sig.renameTo(new File(newSig,sig.getName()));
		}
		
	}
	public static void main(String[] args) {
		DoubleSigRemover test = new DoubleSigRemover();
		File patch = new File("C:/Users/lucas.gomes.COMPROVASP/Documents/Dados de Chamados/17913/Sumitomo_2011");
		for (File file : patch.listFiles()) {
			if(!file.getName().equalsIgnoreCase("Original")&&file.isDirectory()){
			Map<String,String> keys = test.getSigsMap(file);
			test.separaArquivosUnicos(keys.entrySet(),"C:/Temp/Temp");
			}
		}
	}
}
